<template>
  <div class="app">
    <template v-if="routeName !== 'login'">
      <div class="open-menu" title="切换菜单" @mouseover="openMenu" :class="{'active':showMenu}">
        <i :class="showMenu?'el-icon-right':'el-icon-back'"></i>
      </div>
      <div class="app-menu" @mouseleave="hideMenu" :class="{'active':showMenu}">
        <Menu :routeName="routeName"/>
      </div>
    </template>
    <div class="app-main">
      <router-view/>
    </div>
  </div>
</template>

<script>
import {GetOs} from "../wailsjs/go/controller/System";
import Menu from './components/Menu.vue'
export default {
  name: 'AppView',
  components: {
    Menu
  },
  computed: {
    routeName() {
      return this.$route.name;
    }
  },
  data(){
    return {
      showMenu:true
    }
  },
  created() {
    GetOs().then(os => {
      localStorage.setItem("os",os)
      console.log(os)
    })
  },
  methods:{
    openMenu(){
      this.showMenu = !this.showMenu
    },
    hideMenu(e){
      const rect = e.target.getBoundingClientRect();
      const centerX = rect.left + rect.width / 2;
      if (e.clientX < centerX) {
        this.showMenu = false
        console.log('鼠标从左边离开');
      } else {
        console.log('鼠标从右边离开');
      }
    }
  }
}
</script>


<style lang="scss">
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
html,body{
  margin: 0;
  padding: 0;
}
body{
  width: 100vw;
  height: 100vh;
  background: #ffffff;
}
.app{
  position: relative;
  .open-menu{
    width: 28px;
    text-align: center;
    line-height: 36px;
    z-index: 10000;
    position: fixed;
    right: 0;
    bottom: calc((100vh - 25px) / 2);
    color: #191717;
    background: #ffffff;
    border-radius: 32px 0 0 32px;
    box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);
    &.active{
      width: 25px;
      height: 25px;
      line-height: 25px;
      right: 5px;
      bottom: 8px;
      background: #f0f5f6;
      border-radius: 25px;
      color: #76808c;
      text-align: center;
    }
  }
  .app-menu{
    position: absolute;
    right: 0;
    top: 0;
    z-index: 9999;
    width: 0;
    transition: width .5s;
    overflow-x: hidden;
    &.active{
      width: 125px;
      box-shadow: -10px 0px 60px 0px rgba(0, 0, 0, 0.5);
    }
  }
  .app-main{
    width: 100vw;
    height: 100vh;
    overflow: auto;
  }
}
</style>
